<template>
<div class="">
    <div class="pr10">
        <div class="analyItem">
            <p class="analyItemTit tx-center">状态</p>
            <div class="analyItemCon">
                <div class="col-md-12">
                    <p class="col-md-3">
                        <span class="cGreen pr8" title="当前阶段">{{leftInfo.AfterMarketState | stage}}</span>
                    </p>
                    <p class="col-md-3">
                        <span class="cGreen pr8" title="进入该阶段的日期">{{leftInfo.AfterMarketStateTime}}</span>
                    </p>
                    <p class="col-md-3">
                        <span class="cGreen pr8">未开启</span>
                    </p>
                    <span class="circlemark circlemark-lightGreen">正</span>
                </div>
            </div>
        </div>
    </div>
    <div class="thinScroll pr10" v-scrollHeight="84" v-loading="loading">
        <div class="thinScroll-infinite thinScroll"
                v-infinite-scroll="loadMore"
                infinite-scroll-disabled="busy"
                infinite-scroll-immediate-check="false"
                infinite-scroll-distance="0">
            <router-link tag="div" :to="{path:routerPath('quality'), query:{processCode : item.processCode,stage:item.orderStage }}" class="analyItem anItemBor" exact active-class="anItemBor-active"
                v-for="(item, index) in  qualityList" :key='index'
                >
                <p class="analyItemTit tx-center">{{item.processChildName | slice(0,4)}}</p>
                <div class="analyItemCon">
                    <div class="col-md-12">
                        <p class="col-md-8">
                            <span class="cLightGray pr8">编号：</span>
                            <span class="cGreen">{{item.processCode}}</span>
                        </p>
                        <p class="col-md-4">
                            <span class="cLightGray pr8">当前阶段</span>
                            <span class="cGreen">{{item.orderStage | filterOrderStage()}}</span>
                        </p>
                    </div>
                    <span :class="['circlemark', item.orderStage === 5 ? 'circlemark-lightGreen' : 'circlemark-lightRed']">{{item.orderStage === 5 ? '完' : '未'}}</span>
                </div>
            </router-link>
         </div>
    </div>
    <div class="pr10">
        <router-link tag="div" :to="routerPath('default')" class="analyItem anItemBor" active-class="anItemBor-active">
            <p class="analyItemTit tx-center">处理</p>
            <div class="analyItemCon">
                <p class="col-md-12">
                    <span class="cLightGray pr8">总数量：</span>
                    <span class="cGreen">{{qualityData !== null ? qualityData.allCount : 0}}</span>
                </p>
            </div>
        </router-link>
    </div>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
import { getWorkOrderCraftByCondition } from '../Resources/Api/index'
export default {
    data () {
        return {
            loading: true,
            qualityList: [], // 质量订单
            qualityData: null, // 工艺数据
            pageIndex: 1 // 当前页数
        }
    },
    computed: {
        ...mapGetters(['leftInfo', 'userInfo', 'updatePlate'])
    },
    created () {
        this.getWorkOrderCraftByCondition()
    },
    methods: {
        // 到达底部是触发回调
        loadMore () {
            this.pageIndex += 1
            this.getWorkOrderCraftByCondition()
        },
        getWorkOrderCraftByCondition () {
            let _this = this
            // 参数
            let parm = {
                areaId: 0,
                processName: this.leftInfo.orderno,
                orderStage: -2,
                cityId: 0,
                pageIndex: this.pageIndex,
                pageSize: 10000
            }
            getWorkOrderCraftByCondition(parm).then((result) => {
                if (result.data.StatusCode === 1) {
                    _this.qualityList = result.data.Body.workOrderCraftList
                    _this.qualityData = result.data.Body.workOrderCraftCount
                    _this.loading = false
                }
            }).catch((err) => {
                console.log(err)
            })
        },
        // 路由跳转路径拼接
        routerPath (path) {
            return this.$route.matched[1].path + '/' + path
        },
        // 直接进行路由跳转路径
        routerPush (path) {
            this.$router.push(this.$route.matched[1].path + '/' + path)
        }
    },
    watch: {
        leftInfo () {
            this.loading = true
            this.getWorkOrderCraftByCondition()
        },
        updatePlate () {
            this.loading = true
            this.getWorkOrderCraftByCondition()
        }
    },
    filters: {
        // 过滤状态
        filterOrderStage (stage) {
            let value = ''
            switch (stage) {
            case -1:
                value = '待分配'
                break
            case 0:
                value = '未启动'
                break
            case 1:
                value = '工传'
                break
            case 2:
                value = '项验'
                break
            case 3:
                value = '工返'
                break
            case 4:
                value = '客评'
                break
            case 5:
                value = '历史'
                break
            case 6:
                value = '未完成'
                break
            }
            return value
        },
        stage (parone) {
            let value = ''
            switch (parone) {
            case 0:
            case 10:
                value = '审计'
                break
            case 20:
                value = '准备'
                break
            case 30:
                value = '在施'
                break
            case 31:
                value = '施前'
                break
            case 32:
                value = '施中'
                break
            case 33:
                value = '施尾'
                break
            case 40:
                value = '竣工'
                break
            case 50:
                value = '完工'
                break
            case 60:
                value = '历史'
                break
            case 70:
                value = '坏账'
                break
            case 80:
                value = '退单'
                break
            }
            return value
        }
    }
}
</script>
